package com.frogs.ucenter.controller;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.frogs.framework.base.web.BaseController3;
import com.frogs.framework.web.HttpRequestInfo;
import com.frogs.ucenter.service.GoodsService;

@Controller
public class GoodsController extends BaseController3 {
	private static Logger log = LoggerFactory.getLogger(GoodsController.class);  
	private static final String GOODSLIST = "/goods/list";
	
	@Resource
	private GoodsService goodsService;
	
	@RequestMapping(GOODSLIST)
	public JSONObject recommendByTags(HttpServletRequest request,ModelMap model) {
		try {
			HttpRequestInfo requestInfo = new HttpRequestInfo(request);
			
			String tags = requestInfo.getParameter("tags");
    		Integer pageNo = requestInfo.getIntParameter("pageNo", 1);
    		Integer pageSize = requestInfo.getIntParameter("pageSize", 20);
			return goodsService.recommendByTags(tags, pageSize,pageNo);
		} catch (Exception e) {
			log.error("func[recommendByTags] parameterMap[{}] exception[{} - {}] desc[fail]",//
					new Object[] { request.getParameterMap(), e.getMessage(), Arrays.deepToString(e.getStackTrace()) });
		}
		return null;
	}
}
